using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

[Serializable]
//只简单的飞过去，不处理其余的任何逻辑
public class FlyToComponent : BaseComponent
{
    public float ToBuildDotweenIntervel;
    public float JumpPower = 3;
    public float FlyDirection = 0.4f;
    public bool IsFlyScale = false; //是否在飞行的途中缩小
    public void FlyTo(Vector3 targetPosition, Action<Entity> CompleteAction)
    {
        Sequence sequence = DOTween.Sequence();
        sequence.Append(entity.transform.DOJump(targetPosition, JumpPower, 1, FlyDirection)).SetEase(Ease.InQuad);
        sequence.Join(entity.transform.DOLocalRotate(new Vector3(UnityEngine.Random.Range(0, 60), UnityEngine.Random.Range(0, 60), UnityEngine.Random.Range(0, 60)), ToBuildDotweenIntervel));
        if (IsFlyScale) {
            sequence.Join(entity.transform.DOScale(Vector3.zero, 0.4f));
        }
        sequence.AppendCallback(() =>
        {
            CompleteAction?.Invoke(entity);
        });

        sequence.Play();
    }
}
